package com.twu.biblioteca.model;

import java.util.Optional;

/**
 * Created by sgreweni on 29.07.14.
 */
public class Movie extends LibraryItem{
    private final int year;
    private final String director;
    private final Optional<Integer> rating;


    public Movie(String title, int year, String director, Optional<Integer> rating) {
        super(title);
        this.year = year;
        this.director = director;
        this.rating = rating;
    }

    public String getRating() {
        if(rating.isPresent()){
            return rating.get().toString();
        } else {
            return "-";
        }

    }

    public int getYear() {
        return year;
    }

    public String getDirector() {
        return director;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Movie)) return false;
        if (!super.equals(o)) return false;

        Movie movie = (Movie) o;

        if (year != movie.year) return false;
        if (director != null ? !director.equals(movie.director) : movie.director != null) return false;
        if (rating != null ? !rating.equals(movie.rating) : movie.rating != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + year;
        result = 31 * result + (director != null ? director.hashCode() : 0);
        result = 31 * result + (rating != null ? rating.hashCode() : 0);
        return result;
    }
}
